<?php
/**
 * @auther:周卫星
 * @date:2019/11/20
 * @fileName:index.blade.php
 * @fileDesc: 帮助信息列表
 */
?>

@extends('admin_layout.layout')
@section('title', '帮助信息列表')

@push('css')
@endpush
@push('js')
    <script>
        layui.use(['table', 'element', 'form', 'layer', 'common'], function () {
            let $ = layui.$;
            let table = layui.table;
            let form = layui.form;
            let layer = layui.layer;
            let common = layui.common;

            // 获取表格数据的url链接
            let biz_url = $("#bizList").data('url');
            /**
             * 页面表格数据渲染
             */
            table.render({
                elem:"#faqList"
                , id: 'faqList'
                , method: 'get'
                , url: "{{ url('faq/') }}"
                , headers: {
                    type: 'list',
                    isAjax: 'ajax'
                }
                , page: ({
                    layout:['prev', 'page', 'next', 'count']
                    , first: '首页'
                    , last: '尾页'
                })
                , cols:[[
                    {title: 'ID', field: 'id'}
                    , {title: '标题', field: 'title'}
                    , {title: '操作', toolbar: "#operation", fixed: 'right'}
                    /*
                    , {title: '联系地址', field: 'address'}
                    , {title: '联系电话', field: 'tel'}
                    , {title: '联系人', field: 'truename'}
                    , {title: '用户名', field: 'username'}
                    , {title: '操作', toolbar: "#operation", fixed: 'right'}*/
                ]]
                , limit: 20
                , event: true
            });

            /**
             * 页面表格的操作
             */
            /*table.on('tool(bizList)', function (obj) {
                let event_name = obj.event;
                // 查看详情
                if (event_name === 'info'){
                    // 查看商户详情
                    layer.open({
                        type: 2
                        , title: '商户详情'
                        , area: ['50%', '80%']
                        , shadeClose: true
                        , content: $(this).attr('href')
                    });
                    return false;
                }
                // 禁用商户
                if (event_name === 'enabled'){
                    let load = layer.load();
                    // 禁用获取启用商户
                    $.ajax({
                        type: 'post',
                        url: '/biz/update',
                        data: {
                            id: $(this).data('id'),
                            set: {
                                enabled: 0
                            },
                            _token: $(this).data('token')
                        },
                        dataType: 'json',
                        success: function (res) {
                            layer.close(load);
                            if (res.code === 0){
                                common.tipMessage('禁用成功', 6, function () {
                                    table.reload('bizList', {
                                        method: 'get'
                                        , page: {
                                            curr: $(".layui-laypage-em").next().html()
                                        }
                                    });
                                });
                            }else {
                                common.tipMessage('禁用失败');
                            }
                        },
                        error: function (res) {
                            layer.close(load);
                            common.tipMessage(res);
                        },
                        before: function () {
                            load;
                        }
                    });
                }
                // 启用商户
                if (event_name === 'enable'){
                    // 启用商户
                    let load = layer.load();
                    $.ajax({
                        type: 'post',
                        url: '/biz/update',
                        data: {
                            id: $(this).data('id'),
                            set: {
                                enabled: 1
                            },
                            _token: $(this).data('token')
                        },
                        dataType: 'json',
                        success: function (res) {
                            layer.close(load);
                            if (res.code === 0){
                                common.tipMessage('启用成功', 6, function () {
                                    table.reload('bizList', {
                                        method: 'get'
                                        , page: {
                                            curr: $(".layui-laypage-em").next().html()
                                        }
                                    });
                                });
                            }else {
                                common.tipMessage('启用失败');
                            }
                        },
                        error: function (res) {
                            layer.close(load);
                            common.tipMessage(res);
                        },
                        before: function () {
                            load;
                        }
                    });
                }
            });*/

            /**
             * 表格的搜索功能
             * 需要使用到数据表格的重载功能
             */
            form.on('submit(searche_btn)', function (data) {
                /**
                 * 数据表格的重载功能
                 */
                table.reload('bizList', {
                    method: 'get'
                    , where: {
                        biz_name: data.field['biz_name']
                    }
                    , page: {
                        curr: 1
                    }
                });
                return false;
            });

        });
    </script>
@endpush

@section('content')

    <table id="faqList" lay-filter="faqList" data-url="{{ url('faq/') }}">
        <script id="operation" type="text/html">
            <div class="layui-btn-container">
                <a href="{{ url('/faq/edit') }}/@{{ d.id }}" class="layui-btn layui_biz_info">修改</a>
            </div>
        </script>
    </table>
@endsection
